home *** CD-ROM | disk | FTP | other *** search
/ Champak 138 / Volume 138 Aug 19 2011 - Damaged.iso / Games / mom_mania.swf / scripts / MacAndCheeseMomMania.as < prev    next >
Text File  |  2011-08-19  |  7KB  |  223 lines

  1. package
  2. {
  3.    import com.kaboose.games.MomMania.IdEvent;
  4.    import com.kaboose.games.MomMania.MomManiaGame;
  5.    import com.kaboose.games.MomMania.StageSetup;
  6.    import com.kaboose.games.MomMania.UI.MainMenu;
  7.    import flash.display.LoaderInfo;
  8.    import flash.display.Sprite;
  9.    import flash.display.Stage;
  10.    import flash.events.Event;
  11.    import flash.events.HTTPStatusEvent;
  12.    import flash.events.IOErrorEvent;
  13.    import flash.media.Sound;
  14.    import flash.media.SoundChannel;
  15.    import flash.media.SoundTransform;
  16.    import flash.net.URLLoader;
  17.    import flash.net.URLRequest;
  18.    import flash.net.URLVariables;
  19.    
  20.    public class MacAndCheeseMomMania extends Sprite
  21.    {
  22.        
  23.       
  24.       private var menuMusic:Sound;
  25.       
  26.       private var bMuted:Boolean;
  27.       
  28.       private var playCount:Number = 0;
  29.       
  30.       private var menu:MainMenu;
  31.       
  32.       private var menuMusicChan:SoundChannel;
  33.       
  34.       private var myStage:Object;
  35.       
  36.       private var menuRef:String = "MenuScreensMainMenuMainMenu";
  37.       
  38.       private var endSting:Sound;
  39.       
  40.       private var game:MomManiaGame;
  41.       
  42.       public function MacAndCheeseMomMania(param1:Stage)
  43.       {
  44.          menuRef = "MenuScreensMainMenuMainMenu";
  45.          playCount = 0;
  46.          super();
  47.          trace("Main Classed Constructor Called");
  48.          StageSetup.initialize();
  49.          myStage = StageSetup.getInstance();
  50.          myStage.setStage(param1);
  51.          myStage.setDefaultGameStyle();
  52.          menuMusic = new menuLoop();
  53.          endSting = new endTag();
  54.          loadMainMenu();
  55.       }
  56.       
  57.       private function onDefeat(param1:Event) : void
  58.       {
  59.          var _loc2_:SoundTransform = null;
  60.          if(this.menuMusicChan != null)
  61.          {
  62.             this.menuMusicChan.stop();
  63.          }
  64.          this.menuMusicChan = endSting.play(0,1);
  65.          if(bMuted)
  66.          {
  67.             _loc2_ = menuMusicChan.soundTransform;
  68.             _loc2_.volume = 0;
  69.             menuMusicChan.soundTransform = _loc2_;
  70.          }
  71.          this.menuMusicChan.addEventListener(Event.SOUND_COMPLETE,onEndStingComplete);
  72.          trace("GameSetup.onDefeat, You LOST!");
  73.       }
  74.       
  75.       private function onEndStingComplete(param1:Event) : void
  76.       {
  77.          var _loc2_:SoundTransform = null;
  78.          this.menuMusicChan.removeEventListener(Event.SOUND_COMPLETE,onEndStingComplete);
  79.          this.menuMusicChan.stop();
  80.          this.menuMusicChan = menuMusic.play(0,9999999);
  81.          if(bMuted)
  82.          {
  83.             _loc2_ = menuMusicChan.soundTransform;
  84.             _loc2_.volume = 0;
  85.             menuMusicChan.soundTransform = _loc2_;
  86.          }
  87.       }
  88.       
  89.       private function onMainIdle(param1:Event) : void
  90.       {
  91.          if(this.menuMusicChan == null)
  92.          {
  93.             this.menuMusicChan = menuMusic.play(0,9999999);
  94.             trace("setting menuMusicChan: " + this.menuMusicChan);
  95.          }
  96.       }
  97.       
  98.       private function onTrackerError(param1:IOErrorEvent) : void
  99.       {
  100.          trace("error tracking");
  101.       }
  102.       
  103.       private function onStartGame(param1:IdEvent) : void
  104.       {
  105.          trace("----- MainClass onStartGame -----");
  106.          ++playCount;
  107.          if(game == null)
  108.          {
  109.             game = new MomManiaGame(param1.ID);
  110.          }
  111.          else
  112.          {
  113.             game.level = 1;
  114.          }
  115.          if(playCount > 1)
  116.          {
  117.             game.bShowTutorials = false;
  118.          }
  119.          game.setRenderLayer = myStage.game;
  120.          game.addEventListener("onVictory",onVictory);
  121.          game.addEventListener("onDefeat",onDefeat);
  122.          game.addEventListener("onDestroyGame",onDestroyGame);
  123.          game.addEventListener("onMute",onMute);
  124.          game.bMuted = bMuted;
  125.          game.init();
  126.          trackGameplay();
  127.          this.menuMusicChan.stop();
  128.          this.menuMusicChan = null;
  129.       }
  130.       
  131.       private function onVictory(param1:Event) : void
  132.       {
  133.          trace("GameSetup.onVictory, You WIN!");
  134.          if(this.menuMusicChan != null)
  135.          {
  136.             this.menuMusicChan.stop();
  137.          }
  138.          this.menuMusicChan = endSting.play(0,1);
  139.          this.menuMusicChan.addEventListener(Event.SOUND_COMPLETE,onEndStingComplete);
  140.       }
  141.       
  142.       private function trackGameplay() : void
  143.       {
  144.          var _loc1_:Object = null;
  145.          var _loc2_:URLRequest = null;
  146.          var _loc3_:URLVariables = null;
  147.          var _loc4_:URLLoader = null;
  148.          _loc1_ = LoaderInfo(this.root.loaderInfo).parameters;
  149.          if(_loc1_.gameID == null)
  150.          {
  151.             _loc1_.gameID = "9055";
  152.          }
  153.          if(_loc1_.trackerURL == null)
  154.          {
  155.             _loc1_.trackerURL = "http://games.zeeks.com/logGamePlay.php";
  156.          }
  157.          _loc2_ = new URLRequest(_loc1_.trackerURL);
  158.          _loc3_ = new URLVariables();
  159.          _loc3_.gameID = _loc1_.gameID;
  160.          _loc3_.cachekiller = int(Math.random() * 10000000);
  161.          _loc2_.data = _loc3_;
  162.          (_loc4_ = new URLLoader()).addEventListener(HTTPStatusEvent.HTTP_STATUS,onTrackerStatus);
  163.          _loc4_.addEventListener(IOErrorEvent.IO_ERROR,onTrackerError);
  164.          _loc4_.load(_loc2_);
  165.       }
  166.       
  167.       private function onMute(param1:Event) : void
  168.       {
  169.          var _loc2_:SoundTransform = null;
  170.          trace("mainclass onMute()");
  171.          if(bMuted)
  172.          {
  173.             if(this.menuMusicChan != null)
  174.             {
  175.                _loc2_ = menuMusicChan.soundTransform;
  176.                _loc2_.volume = 1;
  177.                menuMusicChan.soundTransform = _loc2_;
  178.             }
  179.             bMuted = false;
  180.          }
  181.          else
  182.          {
  183.             if(this.menuMusicChan != null)
  184.             {
  185.                _loc2_ = menuMusicChan.soundTransform;
  186.                _loc2_.volume = 0;
  187.                menuMusicChan.soundTransform = _loc2_;
  188.             }
  189.             bMuted = true;
  190.          }
  191.       }
  192.       
  193.       private function onDestroyGame(param1:Event) : void
  194.       {
  195.          trace("GameSetup.onDestroyGame");
  196.          game.removeEventListener("onDefeat",onDefeat);
  197.          game.removeEventListener("onVictory",onVictory);
  198.          game.removeEventListener("onDestroyGame",onDestroyGame);
  199.          game = null;
  200.          loadMainMenu();
  201.       }
  202.       
  203.       private function onMainMenu(param1:Event) : void
  204.       {
  205.          trace("GameSetup.onMainMenu");
  206.       }
  207.       
  208.       private function onTrackerStatus(param1:HTTPStatusEvent) : void
  209.       {
  210.          trace("gameplay tracker httpStatusHandler: " + param1);
  211.       }
  212.       
  213.       private function loadMainMenu() : void
  214.       {
  215.          menu = new MainMenu(myStage.menus,UIMainMenu);
  216.          menu.addEventListener("onStartGame",onStartGame);
  217.          menu.addEventListener(IdEvent.ID_TYPE,onStartGame);
  218.          menu.addEventListener("onMainIdle",onMainIdle);
  219.          menu.addEventListener("onMute",onMute);
  220.       }
  221.    }
  222. }
  223.